package edu.zut.cs.software.perfect.attendance.web.spring.controller;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;

import edu.zut.cs.software.perfect.attendance.domain.CourseAttendance;
import edu.zut.cs.software.perfect.attendance.service.CourseAttendanceManager;
import edu.zut.cs.software.perfect.base.web.spring.controller.GenericController;
import edu.zut.cs.software.perfect.course.domain.CourseCategory;

/**
 * 
 * @Title: CourseAttendanceController
 * @Description: TODO
 * @author: lipengde
 * @date 2020年6月1日 上午11:46:12
 */
@Controller
@RequestMapping("/courseAttendance")
@ResponseBody
public class CourseAttendanceController extends GenericController<CourseAttendance, Long, CourseAttendanceManager> {

	CourseAttendanceManager courseAttendanceManager;
	

//	@RequestMapping("/courseAttendance")
//	@ResponseBody
//	public String index() {
//		//String result = "/courseAttendance/index";
//		return JSON.toJSONString(courseAttendanceManager.findAll());
//	}

	@Autowired
	public void setCourseAttendanceManager(CourseAttendanceManager courseAttendanceManager) {
		this.courseAttendanceManager = courseAttendanceManager;
		this.manager = courseAttendanceManager;
	}
	
	@ResponseBody
    @GetMapping(value = "findall", produces = "application/json;charset=utf-8")
    public String findAllCourseAttendance() {
        List<CourseAttendance> courseAttendanceList = this.manager.findAll();
        PageInfo pageInfo = new PageInfo(courseAttendanceList);
        return JSON.toJSONString(pageInfo);
    }
	
	@GetMapping("/findbyid/{id}")
	public String fingById(@PathVariable("id") Long id) {
		Optional<CourseAttendance> result = this.manager.findByCourseId(id);
		return JSON.toJSONString(result);
	}
	
	@GetMapping("/deletebyid/{id}")
	public Boolean deleteById(@PathVariable("id") Long id) {
//		Optional<CourseInformation> courseInformation = this.manager.findByCourseId(id);
		Boolean result = this.manager.deleteById(id);
		return result;
	}
	
}
